package com.lcxw.hxzb.friendcircle.project.system.controller;

import java.util.List;

import com.lcxw.hxzb.friendcircle.framework.web.controller.BaseController;
import com.lcxw.hxzb.friendcircle.framework.web.domain.AjaxResult;
import com.lcxw.hxzb.friendcircle.framework.web.page.TableDataInfo;
import com.lcxw.hxzb.friendcircle.project.system.domain.YwpdBargain;
import com.lcxw.hxzb.friendcircle.project.system.domain.YwpdDynamic;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdBargainService;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 会员砍价明细Controller
 *
 * @author meeting
 * @date 2020-10-14
 */
@Api(description = "会员砍价明细Controller" )
@RestController
@RequestMapping("/client/bargain" )
public class YwpdBargainController extends BaseController {
    @Autowired
    private IYwpdBargainService ywpdBargainService;
    @Autowired
    private IYwpdDynamicService ywpdDynamicService;

/**
 * 查询会员砍价明细列表
 */
@ApiOperation("查询会员砍价明细列表" )
@GetMapping("/list" )
        public AjaxResult list(YwpdBargain ywpdBargain) {
        List<YwpdBargain> list = ywpdBargainService.selectYwpdBargainList(ywpdBargain);
        if(!list.isEmpty()){
            for(YwpdBargain bargain:list){
                YwpdDynamic ywpdDynamic= ywpdDynamicService.queryAllUser(bargain.getUserId()+"");
                bargain.setYwpdDynamic(ywpdDynamic);
            }
        }
        return AjaxResult.success(list);
    }


    /**
     * 查询会员砍价明细列表
     */
    @ApiOperation("是否砍过这个会员" )
    @PostMapping("/skip")
    public AjaxResult skip(@RequestBody YwpdBargain ywpdBargain) {
        List<YwpdBargain> list = ywpdBargainService.selectYwpdBargainList(ywpdBargain);
        if(!list.isEmpty()){
            return AjaxResult.success(list.get(0));
        }
        return AjaxResult.success();
    }


    /**
     * 获取会员砍价明细详细信息
     */
    @ApiOperation("获取会员砍价明细详细信息" )
    @GetMapping(value = "/{bargainId}" )
    public AjaxResult getInfo(@PathVariable("bargainId" ) Long bargainId) {
        return AjaxResult.success(ywpdBargainService.selectYwpdBargainById(bargainId));
    }

    /**
     * 新增会员砍价明细
     */
    @ApiOperation("新增会员砍价明细" )
    @PostMapping
    public AjaxResult add(@RequestBody YwpdBargain ywpdBargain) {
        return toAjax(ywpdBargainService.insertYwpdBargain(ywpdBargain));
    }

    /**
     * 修改会员砍价明细
     */
    @ApiOperation("修改会员砍价明细" )
    @PutMapping
    public AjaxResult edit(@RequestBody YwpdBargain ywpdBargain) {
        return toAjax(ywpdBargainService.updateYwpdBargain(ywpdBargain));
    }

    /**
     * 删除会员砍价明细
     */
    @ApiOperation("删除会员砍价明细" )
    @DeleteMapping("/{bargainIds}" )
    public AjaxResult remove(@PathVariable Long[] bargainIds) {
        return toAjax(ywpdBargainService.deleteYwpdBargainByIds(bargainIds));
    }
}
